﻿using MediatR;
using T_Rbac_APi.Application.Command.Operator;
using T_Rbac_Rep.Interface;

namespace T_Rbac_APi.Application.CommandHandler.OperatorHandler
{
    public class OperatorDeleteListByidHandles : IRequestHandler<OperatorDeleteListCommand, int>
    {
        private readonly IOperator ioperator;

        public OperatorDeleteListByidHandles(IOperator ioperator)
        {
            this.ioperator = ioperator;
        }

        public async Task<int> Handle(OperatorDeleteListCommand request, CancellationToken cancellationToken)
        {
            var Id = (!string.IsNullOrEmpty(request.ids)) ? request.ids.Split(',').Select(x => Convert.ToInt32(x)).ToArray() : null;
            if (Id!=null)
            {
                var list = await ioperator.GetvaluesByResult(x => Id.Contains(x.Oid));
                foreach (var item in list)
                {
                    item.IsDel = true;
                    await ioperator.Update(item);
                }
                return await Task.FromResult(1);
            };
            return await Task.FromResult(-1);
        }
    }
}
